use strict;
use warnings;
use Path::Class;


if(@ARGV < 3){
	print "perl generate_bigwig_ucsc_link.pl INDEX EXT SERVER_IP_DIR\n";
	print "perl generate_bigwig_ucsc_link.pl hg19 bw 220.68.103.84/NGS_link/\n";
	exit;
}


my $INDEX = $ARGV[0];
my $EXT = $ARGV[1];
my $SERVER = $ARGV[2];

my $HEADER = "browser hide all\nbrowser pack knownGene";

my $EACH_ONE = "track type\=bigWig name\=\"";
my $EACH_TWO = "\" db\=$INDEX description\=\"";
my $EACH_THREE = "\" color\=0\,0\,0 visibility\=2 bigDataUrl\=http\:\/\/$SERVER";


my @FILES;
dir('.')->recurse(callback => sub{ 
	my $file = shift;
	if($file =~ /\.$EXT$/){
		push @FILES, $file->absolute->stringify;
	}
});

print "$HEADER\n";
for my $i(0..$#FILES){
	my @info = split/\//, $FILES[$i];

	print $EACH_ONE.$info[$#info].$EACH_TWO.$info[$#info].$EACH_THREE.$info[$#info]."\n";
}

